from flask import g
from flask import session




def do_index_class(index):
    if index == 1:
        return 'first'
    elif index == 2:
        return 'second'
    elif index == 3:
        return 'third'
    else:
        return ''

import functools
def login_user_data(f):
    # 作用就是保留原有函数的一些参数设置  不会被wrapper修改
    @functools.wraps(f)
    def wrapper(*args,**kwargs):
        user_id = session.get('user_id')

        user = None
        if user_id:
            # 有值 说明用户登录了 登录之后查询信息
            from info.models import User
            user = User.query.get(user_id)

        g.user = user

        return f(*args,**kwargs)

    return wrapper